package com.bing.bingPro.common;

import java.util.HashMap;
import java.util.Map;

public class BaseResult<T> {
    private Integer errcode;
    private String errmsg;
    private boolean success;
    private Map ret;

    public BaseResult() {
        this(0, "ok");
    }

    public BaseResult(Integer errcode, String errmsg) {
        this.ret = new HashMap();
        this.errcode = errcode;
        this.errmsg = errmsg;
        this.success = 0 == errcode;
    }

    public BaseResult(Integer errcode, String errmsg, T data) {
        this(errcode, errmsg);
        this.ret.put("data", data);
    }
    public BaseResult(T data) {
        this(0, "ok");
        this.ret.put("data", data);
    }

    public BaseResult(T data, Integer total) {
        this(0, "ok");
        this.ret.put("data", data);
        this.ret.put("total", total);
    }
    public BaseResult setData(T data) {
        this.ret.put("data", data);
        return this;
    }


    public Integer getErrcode() {
        return this.errcode;
    }

    public String getErrmsg() {
        return this.errmsg;
    }

    public boolean isSuccess() {
        return this.success;
    }

    public Map getRet() {
        return this.ret;
    }

    public BaseResult put(String key,Object obj) {
        this.ret.put(key, obj);
        return this;
    }
}
